package com.principle.other;

/**
 * @author 冯志立
 * @create 2019-10-15 15:04
 */
public class Liskov {
    public static void main(String[] args) {
        A a = new A();
        System.out.println(a.func1(3, 2));
        B b = new B();
        System.out.println(b.func1(2, 1));
        System.out.println(b.func2(2, 1));
        //里氏替换原则解决方法就是，让原本的父类和子类继承一个更基础的Base类，将原有的继承关系去掉，采用组合，依赖，聚合等方式替代
        System.out.println(b.func3(3, 8));
    }
}
class A extends Base{
    public int func1(int a, int b){
        return a + b;
    }
}
class B extends Base{
    //如果B类要使用A类，使用组合关系
    private A a = new A();

    public int func1(int a, int b){
        return a / b;
    }
    public int func2(int a, int b){
        return a - b;
    }
    public int func3(int a, int b){
        return this.a.func1(a, b);
    }

}
class Base {

}